package day6;

//字符串转整数
public class oj1 {
    public int StrToInt(String str) {
        char[] ch = str.toCharArray();
        if(ch == null || ch.length == 0) {
            return 0;
        }
        int flg = 1;
        if(ch[0] == '-') {
            flg = -1;
            ch[0] = '0';
        } else if(ch[0] == '+') {
            flg = 1;
            ch[0] = '0';
        }
        int sum = 0;
        for(int i = 0; i < str.length(); i++) {

            if(ch[i] < '0' || ch[i] > '9') {
                sum = 0;
                break;
            }

            sum = sum * 10 + ch[i] - '0';
        }
        return sum * flg;
    }
}
